*** Settings ***
Library           FN

*** Test Cases ***
3.1 用户只存在一个未生效的后付费规则，通过接口查询计费规则，返回为空
    Init Step
    ${interface}    Set Variable    cn.com.servyou.business.obc.facade.FeeRuleQueryFacade
    ${method}    Set Variable    getFeeRule
    ${customerId}    Get UUID
    ${serviceType}    Set Variable    ${PTS_INFO['serviceTypeName']}
    ${serviceCode}    Set Variable    ${PTS_INFO['serviceCode']}
    ${fee_id}    Get timestrap
    ${fee_sql}    ${fee_detail_sql}    Create Fee Rule    ${OBC_FEE_NOT_START}    ${customerId}    2    ${serviceType}    ${fee_id}
    ${year}    ${month}    Get Now Time
    ${settleDeadline}    Get Bill Settle Day    ${year}    ${month}
    Redis Step
    Connect To Redis    ${OBC_REDIS_URL}    ${OBC_REDIS_ALIAS}
    ${redis_key}    Get Fee Rule Key    ${customerId}    ${PTS_INFO['serviceType']}    ${serviceCode}
    Delete Key From Redis    ${OBC_REDIS_ALIAS}    ${redis_key}
    Mysql Step
    Connect To Database    pymysql    ${OBC_DB_URL}    ${OBC_DB_ALIAS}
    Execute Sql String    ${OBC_DB_ALIAS}    DELETE from obc_fee_rule where customer_id = '${customer_id}' or id = ${fee_id}    ${DB_OP_TYPE_DELETE}
    Execute Sql String    ${OBC_DB_ALIAS}    DELETE from obc_fee_rule_detail where fee_rule_id = ${fee_id};    ${DB_OP_TYPE_DELETE}
    Execute Sql String    ${OBC_DB_ALIAS}    ${fee_sql}    ${DB_OP_TYPE_INSERT}
    Execute Sql String    ${OBC_DB_ALIAS}    ${fee_detail_sql}    ${DB_OP_TYPE_INSERT}
    Doing Step
    ${post_data}    Create Dictionary
    Set To Dictionary    ${post_data}    customerId    ${customerId}
    Set To Dictionary    ${post_data}    serviceType    ${serviceType}
    Set To Dictionary    ${post_data}    serviceCode    ${serviceCode}
    ${resp}    Dubbo Invoke    ${OBC_ZK_ADDR}    ${interface}    ${method}    ${post_data}    ${DUBBO_PAMAR_STRING}
    Check Step
    Equal As String    ${resp['entity']}    ${None}
    Redis Key Should Be Exist    ${OBC_REDIS_ALIAS}    ${redis_key}    30
    Validate Schema    ${resp}
    Close Step
    Close Database    ${OBC_DB_ALIAS}
    Close Redis    ${OBC_REDIS_ALIAS}

3.2 用户只存在一个生效中的后付费规则，通过接口查询计费规则，返回该预付费规则信息
    Init Step
    ${interface}    Set Variable    cn.com.servyou.business.obc.facade.FeeRuleQueryFacade
    ${method}    Set Variable    getFeeRule
    ${customerId}    Get UUID
    ${serviceType}    Set Variable    ${PTS_INFO['serviceTypeName']}
    ${serviceCode}    Set Variable    ${PTS_INFO['serviceCode']}
    ${fee_id}    Get timestrap
    ${fee_sql}    ${fee_detail_sql}    Create Fee Rule    ${OBC_FEE_START}    ${customerId}    2    ${serviceType}    ${fee_id}
    ${year}    ${month}    Get Now Time
    Redis Step
    Connect To Redis    ${OBC_REDIS_URL}    ${OBC_REDIS_ALIAS}
    ${redis_key}    Get Fee Rule Key    ${customerId}    ${PTS_INFO['serviceType']}    ${serviceCode}
    Delete Key From Redis    ${OBC_REDIS_ALIAS}    ${redis_key}
    Mysql Step
    Connect To Database    pymysql    ${OBC_DB_URL}    ${OBC_DB_ALIAS}
    Execute Sql String    ${OBC_DB_ALIAS}    DELETE from obc_fee_rule where customer_id = '${customer_id}' or id = ${fee_id}    ${DB_OP_TYPE_DELETE}
    Execute Sql String    ${OBC_DB_ALIAS}    DELETE from obc_fee_rule_detail where fee_rule_id = ${fee_id};    ${DB_OP_TYPE_DELETE}
    Execute Sql String    ${OBC_DB_ALIAS}    ${fee_sql}    ${DB_OP_TYPE_DELETE}
    Execute Sql String    ${OBC_DB_ALIAS}    ${fee_detail_sql}    ${DB_OP_TYPE_DELETE}
    Doing Step
    ${post_data}    Create Dictionary
    Set To Dictionary    ${post_data}    customerId    ${customerId}
    Set To Dictionary    ${post_data}    serviceType    ${serviceType}
    Set To Dictionary    ${post_data}    serviceCode    ${serviceCode}
    ${resp}    Dubbo Invoke    ${OBC_ZK_ADDR}    ${interface}    ${method}    ${post_data}    ${DUBBO_PAMAR_STRING}
    Check Step
    Equal As String    ${resp['entity']['settleDeadline']}    ${None}
    Comment    Equal As String    ${resp['entity']['ruleDetails']}    ${None}
    Equal As String    ${resp['entity']['overUnitPrice']}    ${None}
    ${fee_check_sql}    Check Fee Rule Sql    ${resp['entity']}
    Row Count Is Equal To X    ${OBC_DB_ALIAS}    ${fee_check_sql}    1
    Redis Key Should Be Exist    ${OBC_REDIS_ALIAS}    ${redis_key}    30
    Validate Schema    ${resp}
    Close Step
    Close Database    ${OBC_DB_ALIAS}
    Close Redis    ${OBC_REDIS_ALIAS}

3.3 用户只存在一个已失效的后付费规则，通过接口查询计费规则，返回为空
    Init Step
    ${interface}    Set Variable    cn.com.servyou.business.obc.facade.FeeRuleQueryFacade
    ${method}    Set Variable    getFeeRule
    ${customerId}    Get UUID
    ${serviceType}    Set Variable    ${PTS_INFO['serviceTypeName']}
    ${serviceCode}    Set Variable    ${PTS_INFO['serviceCode']}
    ${fee_id}    Get timestrap
    ${fee_sql}    ${fee_detail_sql}    Create Fee Rule    ${OBC_FEE_END}    ${customerId}    2    ${serviceType}    ${fee_id}
    ${year}    ${month}    Get Now Time
    ${settleDeadline}    Get Bill Settle Day    ${year}    ${month}
    Redis Step
    Connect To Redis    ${OBC_REDIS_URL}    ${OBC_REDIS_ALIAS}
    ${redis_key}    Get Fee Rule Key    ${customerId}    ${PTS_INFO['serviceType']}    ${serviceCode}
    Delete Key From Redis    ${OBC_REDIS_ALIAS}    ${redis_key}
    Mysql Step
    Connect To Database    pymysql    ${OBC_DB_URL}    ${OBC_DB_ALIAS}
    Execute Sql String    ${OBC_DB_ALIAS}    DELETE from obc_fee_rule where customer_id = '${customer_id}' or id = ${fee_id}    ${DB_OP_TYPE_DELETE}
    Execute Sql String    ${OBC_DB_ALIAS}    DELETE from obc_fee_rule_detail where fee_rule_id = ${fee_id};    ${DB_OP_TYPE_DELETE}
    Execute Sql String    ${OBC_DB_ALIAS}    ${fee_sql}    ${DB_OP_TYPE_INSERT}
    Execute Sql String    ${OBC_DB_ALIAS}    ${fee_detail_sql}    ${DB_OP_TYPE_INSERT}
    Doing Step
    ${post_data}    Create Dictionary
    Set To Dictionary    ${post_data}    customerId    ${customerId}
    Set To Dictionary    ${post_data}    serviceType    ${serviceType}
    Set To Dictionary    ${post_data}    serviceCode    ${serviceCode}
    ${resp}    Dubbo Invoke    ${OBC_ZK_ADDR}    ${interface}    ${method}    ${post_data}    ${DUBBO_PAMAR_STRING}
    Check Step
    Equal As String    ${resp['entity']}    ${None}
    Redis Key Should Be Exist    ${OBC_REDIS_ALIAS}    ${redis_key}    30
    Validate Schema    ${resp}
    Close Step
    Close Database    ${OBC_DB_ALIAS}
    Close Redis    ${OBC_REDIS_ALIAS}
